<?php if (!defined('THINK_PATH')) exit();?><!doctype html>
<html>

<head>
    <meta charset="UTF-8">
    <title>演示demo</title>
    <link href="/Public/favicon.ico" type="image/x-icon" rel="shortcut icon">
    <link rel="stylesheet" type="text/css" href="/Public/admin/css/base.css" media="all">
    <link rel="stylesheet" type="text/css" href="/Public/admin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="__STATIC__/iconpicker/css/icon-picker.css">
    <link rel="stylesheet" type="text/css" href="/Public/admin/css/common.css" media="all">
    <link rel="stylesheet" type="text/css" href="/Public/admin/css/module.css">
    <link rel="stylesheet" type="text/css" href="/Public/admin/css/style.css" media="all">
    <script type="text/javascript" src="/Public/admin/js/jquery.js"></script>
    <script type="text/javascript" src="/Public/admin/layui/layui.all.js"></script>

    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <style type="text/css">
        body {
            padding: 10px 0 0 10px
        }
    </style>
</head>

<body style="align-content: center ; width: 60% ;margin-left: 20%;">
    <div class="main-title">
        <h2><?php echo ($meta_title); ?></h2>
    </div>
    <form action="<?php echo U();?>" method="post" class="form-horizontal" enctype="multipart/form-data">
        <div class="form-item">
            <label class="item-label">所属学校</label>
            <div class="controls">
                <select name="school_id" class="me-select">
                    <option value="">--请选择--</option>
                    <?php if(is_array($school_list)): $i = 0; $__LIST__ = $school_list;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?><option value="<?php echo ($key); ?>" <?php if($info['school_id'] == $key): ?>selected<?php endif; ?> ><?php echo ($vo); ?></option><?php endforeach; endif; else: echo "" ;endif; ?>
                </select>
            </div>
        </div>
        <div class="form-item">
            <label class="item-label">姓名<span class="check-tips">*</span></label>
            <div class="controls">
                <input type="text" class="text" name="name" value="<?php echo ($info["name"]); ?>">
            </div>
        </div>
        <div class="form-item">
            <label class="item-label">性别</label>
            <div class="controls">
                <input type="radio" value="0" name="sex" <?php if($info['sex'] == 0): ?>checked<?php endif; ?> >女 &nbsp;&nbsp;
                <input type="radio" value="1" name="sex" <?php if($info['sex'] == 1): ?>checked<?php endif; ?> >男
            </div>
        </div>
        <div class="form-item">
            <label class="item-label">爱好</label>
            <div class="controls">
                <?php if(is_array($hobby_list)): $i = 0; $__LIST__ = $hobby_list;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?><input type="checkbox" value="<?php echo ($key); ?>" name="hobby[]" <?php if(in_array($key,$info['hobby'])): ?>checked<?php endif; ?>><?php echo ($vo); ?> &nbsp;&nbsp;<?php endforeach; endif; else: echo "" ;endif; ?>
            </div>
        </div>
        <div class="form-item">
            <label class="item-label">入学时间</label>
            <div class="controls">
                <?php if($info['admission_time']): ?><input type="date" value="<?php echo (date('Y-m-d',$info["admission_time"])); ?>" name="admission_time">
                    <?php else: ?>
                    <input type="date" name="admission_time"><?php endif; ?>
            </div>
        </div>
        <?php if($info['head_img']): ?><div class="form-item">
                <label class="item-label">上传的照片 <a href="#" id="del" style="margin-left: 30px">删 除</a></label>
                <div class="controls">
                    <?php if(is_array($head_img_list)): foreach($head_img_list as $key=>$vimg): ?><img src="<?php echo ($vimg); ?>" style="border: 2px solid black; border-radius: 5px;"><?php endforeach; endif; ?>
                </div>
            </div><?php endif; ?>
        <div class="layui-upload">
            <button type="button" class="layui-btn" id="manyUpload">多图片上传</button>
            <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
                预览图：
                <div class="layui-upload-list" id="previewImg"></div>
            </blockquote>
            <input type="hidden" name="head_img" id="images">
        </div>
        <div class="form-item">
            <input type="hidden" name="id" value="<?php echo ($info["id"]); ?>" />
            <button class="btn submit-btn" id="submit" type="submit">确 定</button>
            <button class="btn btn-return" onclick="javascript:history.back(-1);return false;">返 回</button>
        </div>
    </form>
</body>

<script type="text/javascript" charset="utf-8">
    $('#del').click(function() {
        if (confirm('是否确定删除照片')) {
            var id = $('input[name="id"]').val();
            // Ajax提交数据
            $.ajax({
                url: "<?php echo U('ajaxDelImg');?>", // 提交到controller的url路径
                type: "post", // 提交方式
                data: {
                    id: id
                }, // data为String类型，必须为 Key/Value 格式。
                dataType: "json", // 服务器端返回的数据类型
                success: function(rst) { // 请求成功后的回调函数，其中的参数data为controller返回的map,也就是说,@ResponseBody将返回的map转化为JSON格式的数据，然后通过data这个参数取JSON数据中的值
                    alert(rst.msg);
                    if (rst.status) {
                        /*删除成功  0.5秒后刷新页面*/
                        setTimeout(function() {
                            location.reload();
                        }, 500);
                    }
                },
            });
        }
    });

    layui.use('upload', function() {
        var $ = layui.jquery,
            upload = layui.upload;
        upload.render({
            elem: '#manyUpload',
            url: '<?php echo U("upload");?>?dir=img',
            multiple: true,
            before: function(obj) {
                obj.preview(function(index, file, result) { //预读本地文件示例，不支持ie8
                    $('#previewImg').append('<img style="width: 200px;height: 200px;"  src="' + result + '" alt="' + file.name + '" class="layui-upload-img">')
                });
            },
            done: function(res) {
                //上传完毕
                console.log(res);
                if (res.type == 1) {
                    var image_path = res.image_path;
                    var thumb = res.thumb_image;
                    var images = $('#images').val();
                    $('#images').val(images + '#' + '/' + image_path + ',' + '/' + thumb); //这里我拼接了图片地址，数据添加时再去解析就行

                } else {
                    layer.msg('文件大小不能超过2M', {
                        icon: 2
                    })
                }
            }
        });

    });
</script>

</html>